package com.atguigu.gmall.order.pay.controller;


import com.atguigu.gmall.common.util.AuthContextHolder;
import com.atguigu.gmall.model.bo.UserIdBo;
import com.atguigu.gmall.model.order.OrderInfo;
import com.atguigu.gmall.order.pay.config.PayTemplate;
import com.atguigu.gmall.order.service.OrderInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/api/payment")
@RestController
public class PayController {


    @Autowired
    PayTemplate payTemplate;

    @Autowired
    OrderInfoService orderInfoService;

    //调到支付宝收银台页面
    @GetMapping(value = "/alipay/submit/{orderId}",produces = "text/html")
    public String alipayPage(@PathVariable("orderId") Long orderId){
        UserIdBo bo = AuthContextHolder.getUserIdBo();
        //1、查出这个要准备支付的订单数据
        OrderInfo orderInfo = orderInfoService.getOrderById(orderId,bo.getUserId());

        //2、根据上面的订单信息生成支付页面
        String payPage = payTemplate.getPayPage(orderInfo);

        return payPage;
    }
}
